namespace DatabaseMigrationTool.Models
{
    public enum DatabaseType
    {
        SqlServer,
        MySql,
        PostgreSql,
        Sqlite,
        DaMeng
    }

    public class DatabaseConnectionInfo
    {
        public DatabaseType DatabaseType { get; set; }
        public string Server { get; set; } = string.Empty;
        public string Port { get; set; } = string.Empty;
        public string Database { get; set; } = string.Empty;
        public string Username { get; set; } = string.Empty;
        public string Password { get; set; } = string.Empty;
        public string ConnectionString { get; set; } = string.Empty;

        public string BuildConnectionString()
        {
            switch (DatabaseType)
            {
                case DatabaseType.SqlServer:
                    return $"Server={Server},{Port};Database={Database};User Id={Username};Password={Password};TrustServerCertificate=True;";
                case DatabaseType.MySql:
                    return $"Server={Server};Port={Port};Database={Database};User={Username};Password={Password};";
                case DatabaseType.PostgreSql:
                    return $"Host={Server};Port={Port};Database={Database};Username={Username};Password={Password};";
                case DatabaseType.Sqlite:
                    return $"Data Source={Database};";
                case DatabaseType.DaMeng:
                    return $"Server={Server};Port={Port};Database={Database};User ID={Username};Password={Password};";
                default:
                    throw new NotImplementedException("不支持的数据库类型");
            }
        }
    }

    public class DatabaseMigrationRequest
    {
        public DatabaseConnectionInfo SourceDatabase { get; set; } = new DatabaseConnectionInfo();
        public DatabaseConnectionInfo TargetDatabase { get; set; } = new DatabaseConnectionInfo();
        public bool MigrateSchema { get; set; } = true;
        public bool MigrateData { get; set; } = true;
        public bool ProcessForeignKeys { get; set; } = true;
        public List<string> SelectedTables { get; set; } = new List<string>();
    }

    // 外键关系模型
    public class ForeignKeyInfo
    {
        public string Name { get; set; } = string.Empty;
        public string TableName { get; set; } = string.Empty;
        public string ColumnName { get; set; } = string.Empty;
        public string ReferencedTableName { get; set; } = string.Empty;
        public string ReferencedColumnName { get; set; } = string.Empty;
        public string DeleteRule { get; set; } = string.Empty; // CASCADE, NO ACTION, SET NULL, etc.
        public string UpdateRule { get; set; } = string.Empty;
    }
}